/* $Id: LanguagesModel.java 129 2011-08-26 05:27:43Z altdotua@gmail.com $ */

package alt.djudge.frontend.server.models;

import java.util.List;
import java.util.HashMap;
import java.util.Map;

import org.hibernate.criterion.Order;

import alt.djudge.frontend.server.Deployment;
import alt.djudge.frontend.server.datatypes.LanguageEntry;


public class LanguagesModel
{
	static CoreInterface<LanguageEntry> core = Deployment.isGAE() ? 
			
		new AbstractBigtableModelCore<LanguageEntry>()
		{
			@Override
			protected Class<LanguageEntry> getEntryClass()
			{
				return LanguageEntry.class;
			}
	
			@Override
			protected Order getOrdering()
			{
				return Order.desc("id");
			}
		}
	:
		new AbstractDBModelCore<LanguageEntry>()
		{
			@Override
			protected Class<LanguageEntry> getEntryClass()
			{
				return LanguageEntry.class;
			}

			@Override
			protected Order getOrdering()
			{
				return Order.asc("id");
			}
		};		
	
	
	public static LanguageEntry getEntry(Long languageId)
	{
		return core.getEntry(languageId);
	}

	public static List<LanguageEntry> getAllEntries()
	{
		return core.getAllEntries();
	}
	
	public static List<LanguageEntry> getEntries(Map<String, Object> map)
	{
		return core.getEntries(map);
	}
	
	public static boolean deleteEntry(Long languageId)
	{
		return core.deleteEntry(languageId);
	}
	
	public static HashMap<Long, LanguageEntry> getEntriesMap()
	{
		List<LanguageEntry> list = getAllEntries();
		HashMap<Long, LanguageEntry> result = new HashMap<Long, LanguageEntry>();
		for (LanguageEntry entry: list)
			result.put(entry.getId(), entry);
		return result;
	}
	
	public static CoreInterface<LanguageEntry> getCore()
	{
		return core.getAdapter();
	}
}
